function [filelist,pathname] = jcb_select_files(pattern,type)

if nargin < 2
    typeselector = '*';
else
    switch type
        case 'spectra'
            typeselector = '*spectra.txt';
        case 'nearfield'
            typeselector = '*nearfield*.txt';
        case 'near field'
            typeselector = '*nearfield*.txt';
        case 'near_field'
            typeselector = '*nearfield*.txt';
        case 'index'
            typeselector = '*index*.txt';
        otherwise
            error('jcb:SelectFiles:WrongType','wrong type selector');
    end
end
if nargin < 1
    pattern = '*';
end

[pathname pattern ext]=fileparts(pattern);
pattern=[pattern ext];
if strcmpi(pattern,'all')
    pattern='b';
end
if ~isempty(pathname)
    pathname = [pathname filesep];
end
filelist = ls(fullfile(pathname,[pattern typeselector]));
filelist = mat2cell(filelist, ...
                    ones(size(filelist,1),1), ...
                    size(filelist,2));

filelist=strtrim(filelist);
end